/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * <p>Project: javaseapp - LinkedList1
 * <p>Powered by webrx On 2021-08-10 10:37:27
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class LinkedList2 {
    public static void main(String[] args) {
        alist();
        llist();
    }

    public static void alist() {
        System.out.println("ArrayList 100万 add");
        long start = System.currentTimeMillis();
        List<String> list = new ArrayList<>();
        Random rand = new Random();
        for (int i = 0; i < 1000000; i++) {
            list.add(getStr(rand.nextInt(20) + 1));
        }
        list.remove(0);
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void llist() {
        System.out.println("LinkedList 100万 add");
        long start = System.currentTimeMillis();
        LinkedList<String> list = new LinkedList<>();
        Random rand = new Random();
        for (int i = 0; i < 1000000; i++) {
            list.add(getStr(rand.nextInt(20) + 1));
        }
        list.removeFirst();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static String getStr(int len) {
        String str = "0123456789abcdefghijklmnolpqrstuvwxyzABCDEFGHIJKLMNOLPQRSTUVWXYZ";
        StringBuilder sbu = new StringBuilder(6);
        Random rand = new Random();
        for (int i = 0; i < len; i++) {
            sbu.append(str.charAt(rand.nextInt(str.length())));
        }
        return sbu.toString();
    }
}
